package activeQM;



import java.util.LinkedList;
import java.util.List;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.activemq.command.ActiveMQObjectMessage;

import Iview.IFormGestionRemota;
import Iview.IFormTerminalEstudiante;
import contenedorSpring.Contenedor;

public class ClienteQMColaEstudiantesActivos implements MessageListener {
	List<String> ips = new  LinkedList<String>();
	@Override
	public void onMessage(Message m) {
		ActiveMQObjectMessage om = (ActiveMQObjectMessage) m;
		try {
			String receivedObject = (String) om.getObject();
			String[] datos = receivedObject.split(";");
			if(!ips.contains(datos[0])){
				ips.add(datos[0]);
				IFormTerminalEstudiante panel =  (IFormTerminalEstudiante) Contenedor.getSingleton().getApplicationContext().getBean("panel");
				panel.setIP(datos[0]);
				panel.setNombre(datos[1]);
				
				IFormGestionRemota forma =  (IFormGestionRemota) Contenedor.getSingleton().getApplicationContext().getBean("gestionRemota");
				forma.setTerminal(panel);
				
				
			}
		} catch (JMSException   e) {
			throw new RuntimeException(
					"An exception occured while trying to get a JMS object:"
							+ e.getMessage(), e);
		}
	}
}
